package codebot.processor.logic;

import codebot.elector.Candidate;
import codebot.elector.Elector;

/**
 * Keeps the score of various languages as they are recognized from the code.
 * The biggest score shows the most likely language.
 */
public final class Score {
  public static Candidate sCFamily;
  public static Candidate sPhp;
  public static Candidate sJavascript;
  public static Candidate sJava;
  public static Candidate sXml;
  
  private Elector mElector;

  /**
   * Reinitializes the score array
   */
  public Score() {
    mElector=new Elector(); 
    sCFamily=new Candidate("CFamily");
    mElector.registerCandidate(sCFamily);
    sJava=new Candidate("Java");
    sJava.support(sCFamily);
    sPhp=new Candidate("PHP");
    sPhp.support(sCFamily);
    sJavascript=new Candidate("Javascript");
    sJavascript.support(sCFamily);
    sXml=new Candidate("XML");
    mElector.registerCandidate(sXml);
  }

  /**
   * Increments the score for a given language.
   * 
   * @param language
   *          = the constant which defines the language
   */
  public final void increment(Candidate language) {
    language.acquireResources(1);
  }

  /**
   * @return Computes the most likely and specialised language from the existing scores
   */
  public final Candidate getLanguage() {
    return (Candidate) mElector.getWinner().getExecutor();
  }
}
